package com.bk.cyxf.lf;

import java.sql.Connection;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jt.classic.system.ISystem;
import jt.classic.system.SimpleAction;
import jt.classic.system.database.SystemDataSource;
import net.sf.json.JSONObject;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.limp.mine.DataTrimmerI;
import org.limp.mine.StringTool;

public class XtbmAction extends SimpleAction {

	public ActionForward getXtbm(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;
		Connection conn = null;
		String id = StringTool.checkString(request.getParameter("id"));
		try {
			SystemDataSource ds = SystemDataSource.getInstance();
			conn = ds.getConnection();
			String sql = "SELECT * FROM APP_XTBM WHERE DI_ID = ?";
			DataTrimmerI trimmer = new DataTrimmerI(conn);
			DataTrimmerI.DataItemList dil = trimmer.createDIL();
			dil.set(id);
			Map xtbmMap = trimmer.searchSingleData(sql, dil);
			request.setAttribute("result", "{success: true, data : "
					+ JSONObject.fromObject(xtbmMap).toString() + "}");
			forward = mapping.findForward("result");
		} catch (Exception ex) {
			ISystem.catchException(request, this, ex);
		} finally {
			SystemDataSource.closeConnection(conn);
		}
		return forward;
	}

}
